package com.bz.xtcx.manager.mapper;

import com.bz.xtcx.manager.entity.LibEnterprise;
import com.bz.xtcx.manager.mapper.provider.LibEnterpriseProvider;
import com.bz.xtcx.manager.persist.conditions.LibCondition;
import com.bz.xtcx.manager.vo.VoQuery;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;

import java.util.List;

public interface LibEnterpriseMapper {

	@Insert("insert into `lib_enterprise`(id, number, credit_level, user_id, form_id, enterprise_name, "
            + " business_license,registered_capital, registered_time,registered_type,country, address,zip_code,"
            + " is_high_new_tech,location_nature,location_nature_other,high_tech_zone,high_tech_zone_other,lpname, lpzw, lpphone, "
            + " lpemail,lxname, lxzw, lxphone, lxemail, stock_code,listed_place,listed_place_other, domain, "
            + " domain_other, product,patent,developer_number,high_title_type,high_title_type_other,"
            + " research_amount, platform, platform_other,is_research_weapon,weapon_three_evidence,management,"
            + " management_name,management_zw,management_phone,project, shared_resources, jmrh_difficulty, "
            + " jmrh_difficulty_other, jmrh_problem, jmrh_suggest, "
			+ " new_drug_num,invention_num,utility_model_num,ic_num,design_num,national_num,"
			+ " software_num,other_invention_num,undergraduate_num,senior_num,high_title_num, "
			+ " rd_amount_last,rd_amount_before,rd_amount_previous,secrecy_one_time,secrecy_two_time,"
			+ " secrecy_three_time,produce_time,supplier_time,plan_apply,jmrh_tech, search_param, status, creater)"
		    + " VALUES(#{id, jdbcType=VARCHAR},"
		    + " #{number, jdbcType=VARCHAR},"
		    + " #{creditLevel, jdbcType=INTEGER},"
		    + " #{userId, jdbcType=VARCHAR},"
		    + " #{formId, jdbcType=VARCHAR},"
		    + " #{name, jdbcType=VARCHAR},"
		    + " #{code, jdbcType=VARCHAR},"
            + " #{registeredCapital, jdbcType=VARCHAR},"
            + " #{registeredTime, jdbcType=VARCHAR},"
            + " #{registeredType, jdbcType=VARCHAR},"
            + " #{country, jdbcType=VARCHAR},"
            + " #{address, jdbcType=VARCHAR},"
            + " #{zipCode, jdbcType=VARCHAR},"
            + " #{isHighNewTech, jdbcType=INTEGER},"
            + " #{locationNature, jdbcType=VARCHAR},"
            + " #{locationNatureOther, jdbcType=VARCHAR},"
            + " #{highTechZone, jdbcType=INTEGER},"
            + " #{highTechZoneOther, jdbcType=VARCHAR},"
            + " #{lpname, jdbcType=VARCHAR},"
            + " #{lpzw, jdbcType=VARCHAR},"
            + " #{lpphone, jdbcType=VARCHAR},"
            + " #{lpemail, jdbcType=VARCHAR},"
		    + " #{lxname, jdbcType=VARCHAR},"
		    + " #{lxzw, jdbcType=VARCHAR},"
		    + " #{lxphone, jdbcType=VARCHAR},"
		    + " #{lxemail, jdbcType=VARCHAR},"
            + " #{stockCode, jdbcType=VARCHAR},"
            + " #{listedPlace, jdbcType=VARCHAR},"
            + " #{listedPlaceOther, jdbcType=VARCHAR},"
		    + " #{domain, jdbcType=VARCHAR},"
            + " #{domainOther, jdbcType=VARCHAR},"
		    + " #{product, jdbcType=VARCHAR},"
            + " #{patent, jdbcType=VARCHAR},"
            + " #{developerNumber, jdbcType=VARCHAR},"
            + " #{highTitleType, jdbcType=VARCHAR},"
            + " #{highTitleTypeOther, jdbcType=VARCHAR},"
            + " #{researchAmount, jdbcType=VARCHAR},"
            + " #{platform, jdbcType=VARCHAR},"
            + " #{platformOther, jdbcType=VARCHAR},"
            + " #{isResearchWeapon, jdbcType=VARCHAR},"
            + " #{weaponThreeEvidence, jdbcType=VARCHAR},"
            + " #{management, jdbcType=VARCHAR},"
            + " #{managementName, jdbcType=VARCHAR},"
            + " #{managementZw, jdbcType=VARCHAR},"
            + " #{managementPhone, jdbcType=VARCHAR},"
            + " #{project, jdbcType=VARCHAR},"
            + " #{sharedResources, jdbcType=VARCHAR},"
            + " #{jmrhDifficulty, jdbcType=VARCHAR},"
            + " #{jmrhDifficultyOther, jdbcType=VARCHAR},"
            + " #{jmrhProblem, jdbcType=VARCHAR},"
            + " #{jmrhSuggest, jdbcType=VARCHAR},"
            + " #{newDrugNum, jdbcType=VARCHAR},"
            + " #{inventionNum, jdbcType=VARCHAR},"
            + " #{utilityModelNum, jdbcType=VARCHAR},"
            + " #{icNum, jdbcType=VARCHAR},"
            + " #{designNum, jdbcType=VARCHAR},"
            + " #{nationalNum, jdbcType=VARCHAR},"
            + " #{softwareNum, jdbcType=VARCHAR},"
            + " #{otherInventionNum, jdbcType=VARCHAR},"
            + " #{undergraduateNum, jdbcType=VARCHAR},"
            + " #{seniorNum, jdbcType=VARCHAR},"
            + " #{highTitleNum, jdbcType=VARCHAR},"
            + " #{rdAmountLast, jdbcType=VARCHAR},"
            + " #{rdAmountBefore, jdbcType=VARCHAR},"
            + " #{rdAmountPrevious, jdbcType=VARCHAR},"
            + " #{secrecyOneTime, jdbcType=VARCHAR},"
            + " #{secrecyTwoTime, jdbcType=VARCHAR},"
            + " #{secrecyThreeTime, jdbcType=VARCHAR},"
            + " #{produceTime, jdbcType=VARCHAR},"
            + " #{supplierTime, jdbcType=VARCHAR},"
            + " #{planApply, jdbcType=VARCHAR},"
            + " #{jmrhTech, jdbcType=VARCHAR},"
			+ " #{searchParam, jdbcType=VARCHAR},"
		    + " #{status, jdbcType=INTEGER},"
		    + " #{creater, jdbcType=VARCHAR})"
		    )
    @SelectKey(before = true, keyProperty = "id", resultType = String.class, statementType = StatementType.STATEMENT, statement="select uuid()")
	int insert(LibEnterprise e);
	
	@Delete("delete from `lib_enterprise` where id = #{id}")
	int del(String id);
	
	@Update("update `lib_enterprise` set "
            + " enterprise_name=#{name, jdbcType=VARCHAR},"
			+ " credit_level=#{creditLevel, jdbcType=VARCHAR},"
			+ " business_license=#{code, jdbcType=VARCHAR},"
			+ " registered_capital=#{registeredCapital, jdbcType=VARCHAR},"
            + " registered_time=#{registeredTime, jdbcType=VARCHAR},"
			+ " registered_type=#{registeredType, jdbcType=VARCHAR},"
            + " country=#{country, jdbcType=VARCHAR},"
            + " address=#{address, jdbcType=VARCHAR},"
            + " zip_code=#{zipCode, jdbcType=VARCHAR},"
			+ " is_high_new_tech=#{isHighNewTech, jdbcType=INTEGER},"
            + " location_nature=#{locationNature, jdbcType=VARCHAR},"
            + " location_nature_other=#{locationNatureOther, jdbcType=VARCHAR},"
            + " high_tech_zone=#{highTechZone, jdbcType=INTEGER},"
            + " high_tech_zone_other=#{highTechZoneOther, jdbcType=VARCHAR},"
            + " lpname=#{lpname, jdbcType=VARCHAR},"
            + " lpzw=#{lpzw, jdbcType=VARCHAR},"
            + " lpphone=#{lpphone, jdbcType=VARCHAR},"
            + " lpemail=#{lpemail, jdbcType=VARCHAR},"
            + " lxname=#{lxname, jdbcType=VARCHAR},"
            + " lxzw=#{lxzw, jdbcType=VARCHAR},"
            + " lxphone=#{lxphone, jdbcType=VARCHAR},"
            + " lxemail=#{lxemail, jdbcType=VARCHAR},"
            + " is_listed=#{isListed, jdbcType=VARCHAR},"
            + " stock_code=#{stockCode, jdbcType=VARCHAR},"
            + " listed_place=#{listedPlace, jdbcType=VARCHAR},"
            + " listed_place_other=#{listedPlaceOther, jdbcType=VARCHAR},"
			+ " domain=#{domain, jdbcType=VARCHAR},"
            + " domain_other=#{domainOther, jdbcType=VARCHAR},"
			+ " product=#{product, jdbcType=VARCHAR},"
            + " patent=#{patent, jdbcType=VARCHAR},"
            + " developer_number=#{developerNumber, jdbcType=VARCHAR},"
            + " high_title_type=#{highTitleType, jdbcType=VARCHAR},"
            + " high_title_type_other=#{highTitleTypeOther, jdbcType=VARCHAR},"
            + " research_amount=#{researchAmount, jdbcType=VARCHAR},"
            + " platform=#{platform, jdbcType=VARCHAR},"
            + " platform_other=#{platformOther, jdbcType=VARCHAR},"
            + " is_research_weapon=#{isResearchWeapon, jdbcType=VARCHAR},"
            + " weapon_three_evidence=#{weaponThreeEvidence, jdbcType=VARCHAR},"
            + " management=#{management, jdbcType=VARCHAR},"
            + " management_name=#{managementName, jdbcType=VARCHAR},"
            + " management_zw=#{managementZw, jdbcType=VARCHAR},"
            + " management_phone=#{managementPhone, jdbcType=VARCHAR},"
            + " project=#{project, jdbcType=VARCHAR},"
            + " shared_resources=#{sharedResources, jdbcType=VARCHAR},"
            + " jmrh_difficulty=#{jmrhDifficulty, jdbcType=VARCHAR},"
            + " jmrh_difficulty_other=#{jmrhDifficultyOther, jdbcType=VARCHAR},"
            + " jmrh_problem=#{jmrhProblem, jdbcType=VARCHAR},"
            + " jmrh_suggest=#{jmrhSuggest, jdbcType=VARCHAR},"
            + " new_drug_num=#{newDrugNum, jdbcType=VARCHAR},"
            + " invention_num=#{inventionNum, jdbcType=VARCHAR},"
            + " utility_model_num=#{utilityModelNum, jdbcType=VARCHAR},"
            + " ic_num=#{icNum, jdbcType=VARCHAR},"
            + " design_num=#{designNum, jdbcType=VARCHAR},"
            + " national_num=#{nationalNum, jdbcType=VARCHAR},"
            + " software_num=#{softwareNum, jdbcType=VARCHAR},"
            + " other_invention_num=#{otherInventionNum, jdbcType=VARCHAR},"
            + " undergraduate_num=#{undergraduateNum, jdbcType=VARCHAR},"
            + " senior_num=#{seniorNum, jdbcType=VARCHAR},"
            + " high_title_num=#{highTitleNum, jdbcType=VARCHAR},"
            + " rd_amount_last=#{rdAmountLast, jdbcType=VARCHAR},"
            + " rd_amount_before=#{rdAmountBefore, jdbcType=VARCHAR},"
            + " rd_amount_previous=#{rdAmountPrevious, jdbcType=VARCHAR},"
            + " secrecy_one_time=#{secrecyOneTime, jdbcType=VARCHAR},"
            + " secrecy_two_time=#{secrecyTwoTime, jdbcType=VARCHAR},"
            + " secrecy_three_time=#{secrecyThreeTime, jdbcType=VARCHAR},"
            + " produce_time=#{produceTime, jdbcType=VARCHAR},"
            + " supplier_time=#{supplierTime, jdbcType=VARCHAR},"
            + " plan_apply=#{planApply, jdbcType=VARCHAR},"
            + " jmrh_tech=#{jmrhTech, jdbcType=VARCHAR},"
            + " search_param=#{searchParam, jdbcType=VARCHAR},"
			+ " status=#{status, jdbcType=INTEGER},"
			+ " updater=#{updater, jdbcType=VARCHAR}"
			+ " where id=#{id}")
	int update(LibEnterprise e);
	
	@Update("update `lib_enterprise` set status=#{status, jdbcType=INTEGER} where id=#{id}")
	int updateStatus(@Param("id")String id, @Param("status")int status);
	
	@Update("update `lib_enterprise` set credit_level=#{creditLevel, jdbcType=INTEGER} where id=#{id}")
	int updateCreditLevel(@Param("id")String id, @Param("creditLevel")int creditLevel);
	
	@SelectProvider(type = LibEnterpriseProvider.class, method = "findByCondition")
	@Results(
		id = "libEnterprise",
		value = {
		    @Result(id = true, property = "id", column = "id"),
		    @Result(property = "number", column = "number"),
		    @Result(property = "creditLevel", column = "credit_level"),
		    @Result(property = "userId", column = "user_id"),
		    @Result(property = "name", column = "enterprise_name"),
		    @Result(property = "code", column = "business_license"),
            @Result(property = "registeredCapital", column = "registered_capital"),
            @Result(property = "registeredTime", column = "registered_time"),
            @Result(property = "registeredType", column = "registered_type"),
            @Result(property = "country", column = "country"),
            @Result(property = "address", column = "address"),
            @Result(property = "zipCode", column = "zip_code"),
            @Result(property = "isHighNewTech", column = "is_high_new_tech"),
            @Result(property = "locationNature", column = "location_nature"),
            @Result(property = "locationNatureOther", column = "location_nature_other"),
            @Result(property = "highTechZone", column = "high_tech_zone"),
            @Result(property = "highTechZoneOther", column = "high_tech_zone_other"),
            @Result(property = "lpname", column = "lpname"),
            @Result(property = "lpzw", column = "lpzw"),
            @Result(property = "lpphone", column = "lpphone"),
            @Result(property = "lpemail", column = "lpemail"),
		    @Result(property = "lxname", column = "lxname"),
		    @Result(property = "lxzw", column = "lxzw"),
		    @Result(property = "lxphone", column = "lxphone"),
		    @Result(property = "lxemail", column = "lxemail"),
            @Result(property = "isListed", column = "is_listed"),
            @Result(property = "stockCode", column = "stock_code"),
            @Result(property = "listedPlace", column = "listed_place"),
            @Result(property = "listedPlaceOther", column = "listed_place_other"),
		    @Result(property = "domain", column = "domain"),
		    @Result(property = "domainOther", column = "domain_other"),
		    @Result(property = "product", column = "product"),
            @Result(property = "patent", column = "patent"),
            @Result(property = "developerNumber", column = "developer_number"),
            @Result(property = "highTitleType", column = "high_title_type"),
            @Result(property = "highTitleTypeOther", column = "high_title_type_other"),
            @Result(property = "researchAmount", column = "research_amount"),
            @Result(property = "platform", column = "platform"),
            @Result(property = "platformOther", column = "platform_other"),
            @Result(property = "isResearchWeapon", column = "is_research_weapon"),
            @Result(property = "weaponThreeEvidence", column = "weapon_three_evidence"),
            @Result(property = "management", column = "management"),
            @Result(property = "managementName", column = "management_name"),
            @Result(property = "managementZw", column = "management_zw"),
            @Result(property = "managementPhone", column = "management_phone"),
            @Result(property = "project", column = "project"),
            @Result(property = "sharedResources", column = "shared_resources"),
            @Result(property = "jmrhDifficulty", column = "jmrh_difficulty"),
            @Result(property = "jmrhDifficultyOther", column = "jmrh_difficulty_other"),
            @Result(property = "jmrhProblem", column = "jmrh_problem"),
            @Result(property = "jmrhSuggest", column = "jmrh_suggest"),
		    @Result(property = "form", column = "form_id", one = @One(select = "com.bz.xtcx.manager.mapper.BusUserFormHisMapper.findById") ),
		    @Result(property = "logo", column = "id", one = @One(select = "com.bz.xtcx.manager.mapper.LibImageMapper.findLogoByLibId") ),
            @Result(property = "newDrugNum", column = "new_drug_num"),
            @Result(property = "inventionNum", column = "invention_num"),
            @Result(property = "utilityModelNum", column = "utility_model_num"),
            @Result(property = "icNum", column = "ic_num"),
            @Result(property = "designNum", column = "design_num"),
            @Result(property = "nationalNum", column = "national_num"),
            @Result(property = "softwareNum", column = "software_num"),
            @Result(property = "otherInventionNum", column = "other_invention_num"),
            @Result(property = "undergraduateNum", column = "undergraduate_num"),
            @Result(property = "seniorNum", column = "senior_num"),
            @Result(property = "highTitleNum", column = "high_title_num"),
            @Result(property = "rdAmountLast", column = "rd_amount_last"),
            @Result(property = "rdAmountBefore", column = "rd_amount_before"),
            @Result(property = "rdAmountPrevious", column = "rd_amount_previous"),
            @Result(property = "secrecyOneTime", column = "secrecy_one_time"),
            @Result(property = "secrecyTwoTime", column = "secrecy_two_time"),
            @Result(property = "secrecyThreeTime", column = "secrecy_three_time"),
            @Result(property = "produceTime", column = "produce_time"),
            @Result(property = "supplierTime", column = "supplier_time"),
            @Result(property = "planApply", column = "plan_apply"),
            @Result(property = "jmrhTech", column = "jmrh_tech"),
            @Result(property = "searchParam", column = "search_param"),
		    @Result(property = "status", column = "status"),
		    @Result(property = "creater", column = "creater"),
		    @Result(property = "createTime", column = "create_time"),
		    @Result(property = "updater", column = "updater"),
		    @Result(property = "updateTime", column = "update_time")
	    }
	)
    List<LibEnterprise> findByCondition(VoQuery e);
	
	@SelectProvider(type = LibEnterpriseProvider.class, method = "findByConditionApi")
	@ResultMap("libEnterprise")
    List<LibEnterprise> findByConditionApi(LibCondition e);
	
	@Select("select * from `lib_enterprise` where user_id = #{userId}")
	@ResultMap("libEnterprise")
	LibEnterprise findByUserId(String userId);
	
	@Select("select * from `lib_enterprise` where enterprise_name = #{name} and business_license = #{code} limit 1")
	@ResultMap("libEnterprise")
	LibEnterprise findByNameAndCode(@Param("name")String name, @Param("code")String code);

	@Select("select * from `lib_enterprise` where id = #{id}")
	@ResultMap("libEnterprise")
	LibEnterprise findById(String id);
	
	@Select("select * from `lib_enterprise` where form_id = #{id}")
	@ResultMap("libEnterprise")
	LibEnterprise findByFormId(String id);
}
